<?php
/**
 * Supplier Stock In Head
 */
class SSiH extends AppModel {
    var $name = 'SSiH';

    var $useTable = 'supplier_stock_in_heads';

    var $belongsTo = array(
            'Supplier', 'Customer', 'Site',
            'User' => array(
                'fields' => array('username', 'name')
        )
    );

    var $hasMany = array(
        'SSi' => array(
            'dependent'    => true
        )
    );

    var $validate = array(
            'stock_in_no' => array(
                        'rule' => array('notEmpty'),
                        'message' => 'Stock in no. is required.',
                        'required' => true,
        ),
            'stock_in_date' => array(
                        'rule' => array('notEmpty'),
                        'message' => 'Stock in date is required.',
                        'required' => true,
        ),
            'stock_in_by' => array(
                    'rule' => 'notEmpty',
                    'message' => 'Stock in by is required.',
                    'required' => true,
        ),
            'supplier_id' => array(
                    'rule' => 'notEmpty',
                    'message' => 'Supplier is required.',
                    'required' => true,
        ),
            'customer_id' => array(
                    'rule' => 'notEmpty',
                    'message' => 'Customer is required.',
                    'required' => true,
        ),
            'site_id' => array(
                    'rule' => 'notEmpty',
                    'message' => 'Site is required.',
                    'required' => true,
        ),
    );

    function beforeSave() {
        // Insert
        if (isset($this->data['SSiH']['stock_in_date'])) {
            $this->data['SSiH']['stock_in_date'] = $this->dateFormatBeforeSave($this->data['SSiH']['stock_in_date']);
        }
        return true;
    }

    function afterFind($results) {
        foreach ($results as &$SSiH) {
            if (isset($SSiH['SSiH']['stock_in_date'])) {
                $SSiH['SSiH']['stock_in_date'] = $this->dateFormatAfterFind($SSiH['SSiH']['stock_in_date']);
            }

        }
        return $results;
    }
}
?>
